<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="员工编号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入员工编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工性别" prop="sex">
        <el-select
          v-model="queryParams.sex"
          placeholder="请选择员工性别"
          clearable
        >
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="education">
        <el-select
          v-model="queryParams.education"
          placeholder="请选择学历"
          clearable
        >
          <el-option
            v-for="dict in dict.type.education"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="证件号码" prop="cardNum">
        <el-input
          v-model="queryParams.cardNum"
          placeholder="请输入证件号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保单属性" prop="property">
        <el-select
          v-model="queryParams.property"
          placeholder="请选择保单属性"
          clearable
        >
          <el-option
            v-for="dict in dict.type.insurance_policy_property"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="投保月份" prop="insuranceStart">
        <el-date-picker clearable
          v-model="queryParams.insuranceStart"
          type="month"
          value-format="yyyy-MM"
          placeholder="请选择投保月份">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="所在单位(二级)" prop="companyId">
        <el-select v-model="queryParams.companyId" placeholder="请选择所在单位" clearable filterable>
          <el-option
            v-for="item in allCompanyList"
            :key="item.id"
            :label="item.nameSecond"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所在合同" prop="agreementId">
        <el-select v-model="queryParams.agreementId" placeholder="请选择所属合同" clearable filterable>
          <el-option
            v-for="item in allCompanyAgreementList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="移动电话" prop="mobilePhone">
        <el-input
          v-model="queryParams.mobilePhone"
          placeholder="请输入移动电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="户籍地址" prop="domicileAddress">
        <el-input
          v-model="queryParams.domicileAddress"
          placeholder="请输入户籍地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位" prop="job">
        <el-input
          v-model="queryParams.job"
          placeholder="请输入岗位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="岗位类别" prop="category">-->
<!--        <el-input-->
<!--          v-model="queryParams.category"-->
<!--          placeholder="请输入岗位类别"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="联系地址" prop="contactAddress">-->
<!--        <el-input-->
<!--          v-model="queryParams.contactAddress"-->
<!--          placeholder="请输入联系地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <!--      <el-form-item label="投保月份" prop="insuranceEnd">-->
      <!--        <el-date-picker clearable-->
      <!--          v-model="queryParams.insuranceEnd"-->
      <!--          type="date"-->
      <!--          value-format="yyyy-MM-dd"-->
      <!--          placeholder="请选择投保月份结束">-->
      <!--        </el-date-picker>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="证件类型" prop="cardType">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.cardType"-->
      <!--          placeholder="请输入证件类型"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="民族" prop="nation">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.nation"-->
      <!--          placeholder="请输入民族"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="匹配状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择匹配状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.employee_match_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['employee:employee:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['employee:employee:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->

<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="info"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['employee:employee:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['employee:employee:export']"
        >导出</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="employeeList" @selection-change="handleSelectionChange" stripe>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center" width="50" />
      <el-table-column label="所在单位(二级)" align="center" prop="hroCompany.nameSecond" width="120" />
      <el-table-column label="所属合同" align="center" prop="agreementId" >
        <template slot-scope="scope">
          {{getAgreementName(scope.row.agreementId)}}
        </template>
      </el-table-column>
      <el-table-column label="员工编号" align="center" prop="code" width="110" />
      <el-table-column label="员工姓名" align="center" prop="name" >
<!--        <template slot-scope="scope">
          <el-link type="primary" @click="handleDetail(scope.row)">{{scope.row.name}}</el-link>
        </template>-->
      </el-table-column>

      <el-table-column label="保单属性" align="center" prop="property" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.insurance_policy_property" :value="scope.row.property"/>
        </template>
      </el-table-column>
      <el-table-column label="生效时间" align="center" prop="insuranceStart" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.insuranceStart, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="失效时间" align="center" prop="insuranceEnd" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.insuranceEnd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="投保月份结束" align="center" prop="insuranceEnd" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.insuranceEnd, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="证件类型" align="center" prop="cardType" />
      <el-table-column label="证件号码" align="center" prop="cardNum" />
<!--      <el-table-column label="民族" align="center" prop="nation" />-->
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="性别" align="center" prop="sex" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="户籍类型" align="center" prop="domicileType" />
      <el-table-column label="学历" align="center" prop="education" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.education" :value="scope.row.education"/>
        </template>
      </el-table-column>

      <el-table-column label="移动电话" align="center" prop="mobilePhone" />
      <el-table-column label="户籍地址" align="center" prop="domicileAddress" />
      <el-table-column label="员工状态" align="center" prop="status"  width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.employee_match_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="岗位" align="center" prop="job" />
<!--      <el-table-column label="岗位类别" align="center" prop="category" />-->
<!--      <el-table-column label="联系地址" align="center" prop="contactAddress" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['employee:employee:edit']"
          >修改详情</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['employee:employee:remove']"-->
<!--          >删除人员</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改投保人员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
<!--        <el-form-item label="员工编号" prop="code">-->
<!--          <el-input v-model="form.code" placeholder="请输入员工编号" />-->
<!--        </el-form-item>-->

        <el-form-item label="所在单位(二级)" prop="companyId">
          <el-select v-model="form.companyId" placeholder="请选择所在单位" clearable filterable>
            <el-option
              v-for="item in allCompanyList"
              :key="item.id"
              :label="item.nameSecond"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="所在合同" prop="agreementId">
          <el-select v-model="form.agreementId" placeholder="请选择所在合同" clearable filterable>
            <el-option
              v-for="item in allCompanyAgreementList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="员工姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入员工姓名" />
        </el-form-item>

        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select
            v-model="form.sex"
            placeholder="请选择性别"
            clearable
          >
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="学历" prop="education">
          <el-select
            v-model="form.education"
            placeholder="请选择学历"
            clearable
          >
            <el-option
              v-for="dict in dict.type.education"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="证件号码" prop="cardNum">
          <el-input v-model="form.cardNum" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="民族" prop="nation">
          <el-input v-model="form.nation" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="保单属性" prop="property">
          <el-select
            v-model="form.property"
            placeholder="请选择保单属性"
            clearable
          >
            <el-option
              v-for="dict in dict.type.insurance_policy_property"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="投保月份" prop="insuranceStart">
          <el-date-picker clearable
            v-model="form.insuranceStart"
            type="month"
            value-format="yyyy-MM"
            placeholder="请选择投保月份">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="投保月份结束" prop="insuranceEnd">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.insuranceEnd"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择投保月份结束">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->

        <el-form-item label="移动电话" prop="mobilePhone">
          <el-input v-model="form.mobilePhone" placeholder="请输入移动电话" />
        </el-form-item>
        <el-form-item label="户籍地址" prop="domicileAddress">
          <el-input v-model="form.domicileAddress" placeholder="请输入户籍地址" />
        </el-form-item>
        <el-form-item label="联系地址" prop="contactAddress">
          <el-input v-model="form.contactAddress" placeholder="请输入联系地址" />
        </el-form-item>
<!--        <el-form-item label="删除状态" prop="delFlag">-->
<!--          <el-input v-model="form.delFlag" placeholder="请输入删除状态" />-->
<!--        </el-form-item>-->
        <el-form-item label="岗位" prop="job">
          <el-input v-model="form.job" placeholder="请输入岗位" />
        </el-form-item>
        <el-form-item label="岗位类别" prop="category">
          <el-input v-model="form.category" placeholder="请输入岗位类别" />
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 导入投保人员名单对话框 -->
    <el-dialog :title="uploadInsEmpMaterial.title" :visible.sync="uploadInsEmpMaterial.open" width="700px">
      <el-form ref="uploadInsEmpForm" :model="uploadInsEmpForm" :rules="uploadInsEmpMaterialRules" label-width="120px" >
        <el-form-item label="客户企业(二级)"  prop="companyId">
          <el-select v-model="uploadInsEmpForm.companyId" placeholder="请选择客户企业" clearable filterable>
            <el-option
              v-for="item in allCompanyList"
              :key="item.id"
              :label="item.nameSecond"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="客户合同"  prop="agreementId">
          <el-select v-model="uploadInsEmpForm.agreementId" placeholder="请选择客户合同" clearable filterable>
            <el-option
              v-for="item in allCompanyAgreementList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="投保月份" prop="insuranceStart">
          <el-date-picker clearable
                          v-model="uploadInsEmpForm.insuranceDate"
                          type="month"
                          value-format="yyyy-MM"
                          placeholder="请选择投保月份">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="备注" prop="remark">-->
<!--          <el-input v-model="uploadInsEmpForm.remark" type="textarea" placeholder="请输入备注" />-->
<!--        </el-form-item>-->
        <el-form-item label="上传附件" >
          <el-upload
            ref="uploadInsEmpMaterial"
            :limit="1"
            :file-list="importInsEmpList"
            accept=".xlsx, .xls"
            action=""
            :disabled="uploadInsEmpMaterial.isUploading"
            :on-progress="handleUploadInsEmpProgress"
            :on-success="handleUploadInsEmpSuccess"
            :on-change="handleUploadInsEmpChange"
            :auto-upload="false"
            drag
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处，或
              <em>点击上传</em>
            </div>
            <div class="el-upload__tip" slot="tip">
              <!--          <el-checkbox v-model="uploadInsEmpMaterial.updateSupport" />是否更新已经存在的用户数据-->
              <el-link type="info" style="font-size:16px;color:dodgerblue" @click="importTemplate">下载模板</el-link>
            </div>
            <div class="el-upload__tip" style="color:red" slot="tip">提示：仅支持单文件导入，且格式为“xls”或“xlsx”！</div>
          </el-upload>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitUploadInsEmpForm">确 定</el-button>
        <el-button @click="cancelUploadInsEmpForm">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  listEmployee,
  getEmployee,
  delEmployee,
  addEmployee,
  updateEmployee,
  uploadEmpIns
} from "@/api/employee/employee";
import {getToken} from "@/utils/auth";
import {listAllCompanyAgreement} from "@/api/company_agreement/companyagreement";
import {listAllCompany} from "@/api/company/company";
export default {
  name: "Employee",
  dicts: ['education','employee_match_status','insurance_policy_property','sys_user_sex',],

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 投保人员表格数据
      employeeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        orderByColumn:'m.create_time',
        isAsc:'desc',
        pageNum: 1,
        pageSize: 10,
        name: null,
        code: null,
        property: null,
        insuranceStart: null,
        insuranceEnd: null,
        cardType: null,
        cardNum: null,
        nation: null,
        age: null,
        sex: null,
        domicileType: null,
        education: null,
        companyId: null,
        mobilePhone: null,
        domicileAddress: null,
        status: null,
        job: null,
        category: null,
        contactAddress: null,
        agreementId:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        age: [
          { required: true, message: "年龄不能为空", trigger: "blur" }
        ],
      },
      // 导入投保人员名单
      uploadInsEmpMaterial: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/api/employee/addExcel"
      },

      uploadInsEmpForm:{},

      uploadInsEmpMaterialRules:{
        companyId: [{ required: true, message: "请选择客户企业", trigger: "blur" }],
      },
      importInsEmpList:[],
      allCompanyList: [],
      allCompanyAgreementList: [],
    };
  },
  created() {
    this.getList();
    this.getCompanyList();
    this.getCompanyAgreementList();
  },
  methods: {
    /** 查询投保人员列表 */
    getList() {
      this.loading = true;
      listEmployee(this.queryParams).then(response => {
        this.employeeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 获取客户企业列表
    getCompanyList(){
      let q= {};
      listAllCompany(q).then(response => {
        this.allCompanyList = response;
      });
    },
    // 获取客户合同列表
    getCompanyAgreementList(){
      let q= {};
      listAllCompanyAgreement(q).then(response => {
        this.allCompanyAgreementList = response;
      });
    },
    //表格中回显客户合同名称
    getAgreementName(id) {
      if (!id) {
        return null;
      }
      let name = null;
      this.allCompanyAgreementList.forEach((item, i) => {
        if (item.id == id){
          name = item.name;
        }
      });
      return name;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        code: null,
        property: null,
        insuranceStart: null,
        insuranceEnd: null,
        cardType: null,
        cardNum: null,
        nation: null,
        age: null,
        sex: null,
        domicileType: null,
        education: null,
        companyId: null,
        mobilePhone: null,
        domicileAddress: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        job: null,
        category: null,
        contactAddress: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加员工";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEmployee(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改员工";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEmployee(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEmployee(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除员工编号为"' + ids + '"的数据项？').then(function() {
        return delEmployee(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('employee/employee/export', {
        ...this.queryParams
      }, `employee_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.uploadInsEmpForm = {};
      this.uploadInsEmpMaterial.title = "导入投保人员名单";
      this.uploadInsEmpMaterial.open = true;
    },
    //投保人员导入中
    handleUploadInsEmpProgress(event, file, fileList) {
      this.uploadInsEmpMaterial.isUploading = true;
    },
    // 投保人员导入成功处理
    handleUploadInsEmpSuccess(response, file, fileList) {
      this.uploadInsEmpMaterial.open = false;
      this.uploadInsEmpMaterial.isUploading = false;
      this.$refs.uploadInsEmpMaterial.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    handleUploadInsEmpChange(file, fileList){
      this.importInsEmpList = fileList;
    },

    // 提交导入投保人员
    submitUploadInsEmpForm(){
      this.$refs["uploadInsEmpForm"].validate(valid => {
        if (valid) {
          let uploadInsEmpForm = new FormData();
          if (this.importInsEmpList.length > 0 && this.importInsEmpList[0] != null) {
            uploadInsEmpForm.append('file', this.importInsEmpList[0].raw);
          }
          uploadInsEmpForm.append('companyId', this.uploadInsEmpForm.companyId);
          uploadInsEmpForm.append('insuranceDate', this.uploadInsEmpForm.insuranceDate);
          uploadInsEmpForm.append('agreementId', this.uploadInsEmpForm.agreementId);
          // console.log(uploadInsEmpForm);
          uploadEmpIns(uploadInsEmpForm).then(response => {
            if (response.code === 200){
              this.$modal.msgSuccess("导入成功");
              this.loading = false;
              this.uploadInsEmpMaterial.open = false;
              this.uploadInsEmpForm = {};
              this.importInsEmpList = [];
              this.getList();
            }else {
              this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
            }
          });
        }
      });
    },
    //取消上传历史理赔
    cancelUploadInsEmpForm(){
      this.uploadInsEmpMaterial.open = false;
      this.importInsEmpList = [];
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('employee/employee/downloadTemplate', {
      }, `insure_employee_template_${new Date().getTime()}.xlsx`)
    },

    handleDetail(row){
      //需要传的数据
      const data = row.id;
      //路由跳转到新页面
      this.$router.push({  //核心语句
        path:'/center_insured/employeeproject',  //跳转的路径
        query:{             //路由传参时push和query搭配使用 ，作用时传递参数
          employeeId:data,
        }
      })
    },

    //导出投保明细报表
    exportInsuranceDetail(){
      this.download('reportGeneration/insuranceDetail', {
        ...this.queryParams
      }, `insuranceDetail_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
